package com.example.mydesignmodule.adapter;

import com.example.mydesignmodule.factory.Car;
import com.example.mydesignmodule.factory.CarType;

/**
 * @author tgw
 * @date 2021/2/26
 * @describe
 */
public class MediaFactory {

    public static <T extends Media> T createdCar(Class<T> cla) {
        Media mediaPlayer = null;
        try {
            mediaPlayer = (Media) Class.forName(cla.getName()).newInstance();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return (T) mediaPlayer;
    }

    public static <T extends CarType> T createdCarType(Class<T> cla) {
        CarType carType = null;
        try {
            carType = (CarType) Class.forName(cla.getName()).newInstance();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return (T) carType;
    }
}
